package com.villaday.idf.adapter3;

import android.content.Context;
import android.graphics.Paint;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.model3.PreSalesEntity;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.SharedPreferencesUtil;

public class HomeType3Adapter extends AbsRecyclerViewAdapter<PreSalesEntity.BodyBean.ListBean> {
    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;
    private String roleType;

    public HomeType3Adapter(Context context, OnAdapterCallbackListener onAdapterCallbackListener, View.OnClickListener onClickListener) {
        super(context, R.layout.item_home2v_type2, R.layout.item_page_loading);
        this.onAdapterCallbackListener = onAdapterCallbackListener;
        this.onClickListener = onClickListener;

        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();


    }

    public void setRoleType() {
        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();
    }

    @Override
    public int getItemType(PreSalesEntity.BodyBean.ListBean d) {
        return d.getMyType();
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, PreSalesEntity.BodyBean.ListBean d, int position) {
        try {
            switch (d.getMyType()) {
                case 0:
                    holder.bindSimpleDraweeView(R.id.sdv, d.getImageUrl())
                            .bindTextViewWithHtml(R.id.tv_priceFuHao, "&yen;")

                            .bindTextView(R.id.tv_title, d.getName())
                            .bindTextView(R.id.tv_price, d.getCurrentPrice())
                            .bindTextViewWithHtml(R.id.tv_yuanjia, "&yen;" + (d.getOriginalPrice()))
                            .bindTextView(R.id.tv_zhe, d.getDiscountRate() + "折")

                            .bindTextViewWithHtml(R.id.tv_Zhuan, "立返" + "&yen;" + (d.getRebateAmount()))
                            .setViewVisible(R.id.ll_Zhuan, "0".equals(roleType) ? View.GONE : (d.getRebateAmount() == null || "0".equals(d.getRebateAmount()) ? View.GONE : View.VISIBLE))
                            .bindTextView(R.id.date, d.getSaleTips())

                            .setViewVisible(R.id.tv_zhuanNum, "0".equals(roleType) ? View.GONE : (d.getExtraRebateAmount() == null || "0".equals(d.getExtraRebateAmount())) ? View.GONE : View.VISIBLE)
                            .bindTextViewWithHtml(R.id.tv_zhuanNum, "加返" + "&yen;" + (d.getExtraRebateAmount()))

                            .setViewVisible(R.id.img_zhuanfa, "0".equals(roleType) ? View.INVISIBLE : d.getPermission().isAllowShare() ? View.VISIBLE : View.INVISIBLE)
                            .setViewVisible(R.id.tv_chaodi, TextUtils.isEmpty(d.getTags().get(0)) ? View.GONE : View.VISIBLE)
                            .bindTextView(R.id.tv_chaodi, (d.getTags() != null && d.getTags().size() > 0) ? d.getTags().get(0) : "");

                    ImageView imgZhuanfa = (ImageView) holder.getView(R.id.img_zhuanfa);
                    imgZhuanfa.setOnClickListener(onClickListener);
                    imgZhuanfa.setTag(position);
                    TextView view = (TextView) holder.getView(R.id.tv_yuanjia);

                    //添加删除线
                    view.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_chaodi), false);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_priceFuHao), true);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_price), true);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_yuanjia), false);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_Zhuan), false);
                    break;
                case 1:
                    onAdapterCallbackListener.onCallback();
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}

